package assets
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	import model.AppModel;
	
	public class Piramide extends Sprite
	{
		//properties
		private var appModel:AppModel;
		private var rijCardCount:Number;
		private var card:Card;
		private var cardName:String;
		private var xPos:uint;
		private var yPos:uint;
		private var random:Number;
		private var bredeRij:Number;
		private var totalBrede:Number;
		
		public function Piramide()
		{
			trace("constructor [piramide]");
			this.appModel = AppModel.getInstance();
			
			appModel.rijCount = 5;
			yPos = (154 + 3)* (appModel.rijCount - 1);
			rijCardCount = appModel.rijCount;
			totalBrede = rijCardCount*(154 + 3);
			for(var i:uint = 1;i<=appModel.rijCount;i++){
				for(var j:uint = 1;j<=rijCardCount;j++){
					random = appModel.random(0,appModel.kaartenArr.length - 1)
					cardName = appModel.kaartenArr[random];
					removeCardFromDeck();
					card = new Card(cardName);
					card.x = xPos;
					if(i != appModel.rijCount){
						card.y = yPos;
					}
					addChild(card);
					xPos += card.width + 3;
					//trace("aantal kaarten van de rij"+i+": "+j);
				}
				bredeRij = ((j-1)*(card.width + 3));
				xPos = totalBrede/2 - bredeRij/2 - card.width/2 + ((j-1)*3);
				yPos -= card.height + 3;
				rijCardCount--;
			}
			trace("kaarten piramide: "+appModel.kaartenPiramideArr);
		}
		
		private function removeCardFromDeck():void{
			appModel.kaartenPiramideArr.push(cardName);
			appModel.kaartenArr.splice(random,1);
			//trace("aantal Kaarten: "+appModel.kaartenArr.length);
		}
	}
}